import React from 'react';
import {HashRouter, Redirect, Router, Route, Switch, Lifecycle} from 'react-router-dom';
import {createHashHistory, createBrowserHistory} from 'history';
import redux, {memus, memu_index, store, mumesData} from '../redux'
import Home from '../components/common/Home'

const $router = createHashHistory()

$router.listen((route, type) => {
    route = route || {
        hash: "",
        pathname: "/",
        search: "",
        state: ""
    }
    memu_index.dispatch( memus.getState().findIndex(x => x.t_path == route.pathname))
})

React.Component.prototype.$router = $router;

const router = {
    BasicRoute() {
        return (
            <HashRouter>
                <Switch>
                    <Route path="/" component={Home}></Route>
                    <Redirect path="*" to="/"/>
                </Switch>
            </HashRouter>
        )
    },
    extRoute() {
        return (
            <HashRouter>
                <Switch>
                    {
                        mumesData.map((x, i) => {
                            return (
                                <Route exact path={x.t_path} key={i} component={x.component}/>
                            )
                        })
                    }
                </Switch>
            </HashRouter>
        )
    }

}


export default router.BasicRoute;
export const extRoute = router.extRoute;